#ifndef REMOTEDATABASE_H
#define REMOTEDATABASE_H

#include <QObject>
#include <QDebug>
#include <QCryptographicHash>
#include <QNetworkInterface>
#include <QVariantList>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QSslConfiguration>
#include "localconfig.h"

class RemoteDataBase : public QObject
{
    Q_OBJECT
public:
    explicit RemoteDataBase(QObject *parent = nullptr);
    Q_INVOKABLE bool userRegister(QString,QString,int);//用户注册
    Q_INVOKABLE bool userLogin(int,QString);//用户登录
    Q_INVOKABLE bool userLoginAuto(int,QString);//用户自动登录
    Q_INVOKABLE bool saveLinggen(int,int);//存储用户灵根
    Q_INVOKABLE bool saveExperience(int,int,int,int);//存储用户经验值
    Q_INVOKABLE bool sendChatMessage(int,int,QString);//用户自动登录
    Q_INVOKABLE void sendRequest(const QString &inputText);//发送deepseek请求
    //Q_INVOKABLE bool writeStickyNote(int,QString,int64_t,int64_t);//写入便签纸
    //Q_INVOKABLE QVariantList readDataSN(int);//读取用户便签
    //Q_INVOKABLE bool delStickyNote(int,int);//删除用户便签
    LocalConfig localConfig;

public slots:
    //void getUsers();
    //void addUser(const QString &username, const QString &email);

private slots:
    void handleGetResponse();
    void handlePostResponse();
    void handlePostExperience();
    void handleResponse(QNetworkReply *reply);

private:
    QString getLocalIPAddress()const;
    QNetworkAccessManager *manager;
    QString apiKey = "sk-0b099d40a1cd4611895c170f365e1faf";

signals:
    void userReceived(const QString &message,const QJsonArray &users);
    void chatMessageReceived(const QJsonArray &chatMessage);
    void userAdded(const bool success, const double &message);
    void responseReceived(const QString &response);
};

#endif // REMOTEDATABASE_H
